package com.bestcem.xm.ticket.service.manager.notify;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bestcem.xm.ticket.dao.AlertRecordDao;
import com.bestcem.xm.ticket.entity.mongo.Record;
import com.bestcem.xm.ticket.entity.mongo.Ticket;
import com.bestcem.xm.ticket.grpc.client.TicketSurveyGrpcService;
import com.bestcem.xm.ticket.grpc.client.dto.survey.RespondentDTO;
import com.bestcem.xm.ticket.grpc.client.enums.survey.CustomTypeEnum;
import com.bestcem.xm.ticket.service.manager.notify.dto.RespondentAnswerDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;

/**
 * @author gy.liu
 * @version 1.0
 * @date 2021/11/18 19:28
 **/
@Slf4j
@Component
public class SurveyParseManager {

    @Resource
    TicketSurveyGrpcService ticketSurveyGrpcService;

    @Resource
    AlertRecordDao alertRecordDao;


    /**
     * 获取工单通知中的 问卷题目 字段数据
     *
     * @param ticket  工单
     * @param cidList 需要的题目
     * @return 问卷题目 字段数据
     * @author XiaoYunSong <ys.xiao@idiaoyan.com>
     * @date 2021/11/26 18:18
     */
    @Nonnull
    public Map<String, String> getNotifyQuestion(Ticket ticket, Set<String> cidList) {
        if (Objects.isNull(ticket) || CollectionUtils.isEmpty(cidList)) {
            if (log.isInfoEnabled()) {
                log.info("[Ticket] getNotifyQuestion null error {}-{}", Objects.isNull(ticket), CollectionUtils.isEmpty(cidList));
            }
            return new HashMap<>();
        }
        if (log.isInfoEnabled()) {
            log.info("[Ticket] getNotifyQuestion TicketId {} CidList {}", ticket.getId(), cidList);
        }

        // 查询预警记录
        Record record = alertRecordDao.findById(ticket.getAlertRecordId());
        if (Objects.isNull(record) || Objects.isNull(record.getData())) {
            log.error("[Ticket] getNotifyQuestion record null error {}", ticket.getAlertRecordId());
            return new HashMap<>();
        }
        // 获取答卷
        RespondentDTO resp = ticketSurveyGrpcService.getRespondent(record.getRspdSeq(), true, false, true,
                null, null, null,record.getQProjectId());
        if (Objects.isNull(resp) || Objects.isNull(resp.getAnswers())) {
            return new HashMap<>();
        }

        if (log.isDebugEnabled()) {
            log.debug("[Ticket] getNotifyQuestion TicketId {} resp: {}", ticket.getId(), resp);
        }

        // 没有答案
        if ('{' == resp.getAnswers().charAt(0)) {
            return new HashMap<>();
        }

        List<RespondentAnswerDTO> answers = JSONArray.parseArray(resp.getAnswers(), RespondentAnswerDTO.class);
        if (answers.size() <= 0) {
            return new HashMap<>();
        }

        Map<String, RespondentAnswerDTO> answerMap = new HashMap<>();
        for (RespondentAnswerDTO answer : answers) {
            answerMap.put(answer.getCid(), answer);
        }
        // 解析答卷
        Map<String, String> result = parseAnswer(answerMap, cidList);
        if (log.isInfoEnabled()) {
            log.info("[Ticket] parseAnswer parse result {}", result);
        }
        return result;
    }


    /**
     * 解析题目
     *
     * @param answerDTOMap 所有的题目和答案
     * @param cidList      需要的题目
     * @return 解析结果
     * @author XiaoYunSong <ys.xiao@idiaoyan.com>
     * @date 2021/11/26 18:17
     */
    @Nonnull
    private Map<String, String> parseAnswer(Map<String, RespondentAnswerDTO> answerDTOMap, Set<String> cidList) {
        Map<String, String> result = new HashMap<>();

        for (String cid : cidList) {
            RespondentAnswerDTO answerDTO = answerDTOMap.get(cid);
            if (Objects.isNull(answerDTO)) {
                if (log.isInfoEnabled()) {
                    log.info("[Ticket] SurveyParseUtil parseAnswer 无 {} 题", cid);
                }
                continue;
            }
            if (ObjectUtils.isEmpty(answerDTO.getAnswer())) {
                if (log.isInfoEnabled()) {
                    log.info("[Ticket] SurveyParseUtil parseAnswer {} 题无答案", cid);
                }
                continue;
            }
            CustomTypeEnum type = CustomTypeEnum.getByName(answerDTO.getCustomType());
            if (Objects.isNull(type)) {
                if (log.isInfoEnabled()) {
                    log.info("[Ticket] SurveyParseUtil parseAnswer {} 题类型异常 {}", cid, answerDTO.getCustomType());
                }
                continue;
            }
            try {
                // 解析题目
                String answer = parseAnswer(type, answerDTO);
                if (!ObjectUtils.isEmpty(answer)) {
                    result.put(cid, answer);
                }
            } catch (Exception e) {
                log.error("[Ticket] getNotifyQuestion parseAnswer error {}", cid);
            }
        }

        return result;
    }


    /**
     * 解析题目和答案
     *
     * @param type      题目类型
     * @param answerDTO 题目答案和问题
     * @return 解析结果
     * @author XiaoYunSong <ys.xiao@idiaoyan.com>
     * @date 2021/11/26 18:19
     */
    @Nullable
    private String parseAnswer(CustomTypeEnum type, RespondentAnswerDTO answerDTO) {
        StringBuilder sbl = new StringBuilder();
        // 题目标题
        sbl.append(answerDTO.getCid()).append(": ").append(answerDTO.getTitle());
        // 题目类型
        sbl.append(" [").append(type.getInfo()).append("] ");

        // 单选题 | 多选题 | 性别题 | 年龄题 | 学历题 | 职业题
        if (CustomTypeEnum.SINGLE.equals(type) ||
                CustomTypeEnum.MULTIPLE.equals(type) ||
                CustomTypeEnum.INFO_SEX.equals(type) ||
                CustomTypeEnum.INFO_AGE.equals(type) ||
                CustomTypeEnum.INFO_EDUCATION.equals(type) ||
                CustomTypeEnum.INFO_OCCUPATION.equals(type)) {
            JSONArray options = JSON.parseArray(answerDTO.getAnswer());
            if (CollectionUtils.isEmpty(options)) {
                log.error("[Ticket] getNotifyQuestion parseAnswer error {}-{}", type.getName(), answerDTO);
                return null;
            }
            sbl.append("  ");
            for (int i = 0; i < options.size(); i++) {
                JSONObject option = options.getJSONObject(i);
                sbl.append(option.getString("title"));
                if (option.containsKey("open")) {
                    sbl.append("（").append(option.getString("open")).append("）");
                }
                sbl.append(" | ");
            }
            return sbl.delete(sbl.length() - 3, sbl.length()).toString();
        }

        // 级联题 | 行业题
        if (CustomTypeEnum.CASCADER.equals(type) ||
                CustomTypeEnum.INFO_INDUSTRY.equals(type)) {
            JSONArray options = JSON.parseArray(answerDTO.getAnswer());
            if (CollectionUtils.isEmpty(options)) {
                log.error("[Ticket] getNotifyQuestion parseAnswer error {}-{}", type.getName(), answerDTO);
                return null;
            }
            sbl.append("  ");
            for (int i = 0; i < options.size(); i++) {
                JSONObject option = options.getJSONObject(i);
                sbl.append(option.getString("title")).append("-");
            }
            return sbl.delete(sbl.length() - 1, sbl.length()).toString();
        }

        // 填空题
        if (CustomTypeEnum.BLANK.equals(type)) {
            JSONArray blanks = JSON.parseArray(answerDTO.getAnswer());
            if (CollectionUtils.isEmpty(blanks)) {
                log.error("[Ticket] getNotifyQuestion parseAnswer error {}-{}", type.getName(), answerDTO);
                return null;
            }
            sbl.append("  ");
            for (int i = 0; i < blanks.size(); i++) {
                JSONObject blank = blanks.getJSONObject(i);
                sbl.append(blank.getString("blank")).append(" ");
            }
            return sbl.delete(sbl.length() - 1, sbl.length()).toString();
        }

        // 多项填空题
        if (CustomTypeEnum.MULTIPLE_BLANK.equals(type)) {
            JSONArray blanks = JSON.parseArray(answerDTO.getAnswer());
            if (CollectionUtils.isEmpty(blanks)) {
                log.error("[Ticket] getNotifyQuestion parseAnswer error {}-{}", type.getName(), answerDTO);
                return null;
            }
            sbl.append("  ");
            for (int i = 0; i < blanks.size(); i++) {
                JSONObject blank = blanks.getJSONObject(i);
                sbl.append(blank.getString("title"));
                sbl.append("（").append(blank.getString("blank")).append("）");
                sbl.append(" | ");
            }
            return sbl.delete(sbl.length() - 3, sbl.length()).toString();
        }

        // 打分题 | 打分题 | 游标打分题 | 游标打分题
        if (CustomTypeEnum.STAR_SCORE.equals(type) ||
                CustomTypeEnum.STAR.equals(type) ||
                CustomTypeEnum.CURSOR.equals(type) ||
                CustomTypeEnum.CURSOR_SCORE.equals(type)) {
            JSONArray options = JSON.parseArray(answerDTO.getAnswer());
            if (CollectionUtils.isEmpty(options)) {
                log.error("[Ticket] getNotifyQuestion parseAnswer error {}-{}", type.getName(), answerDTO);
                return null;
            }
            if (options.size() == 1) {
                sbl.append("分数: ").append(options.getJSONObject(0).getString("score"));
                return sbl.toString();
            } else {
                for (int i = 0; i < options.size(); i++) {
                    JSONObject option = options.getJSONObject(i);
                    sbl.append(option.getString("title")).append("：");
                    sbl.append(option.getString("score")).append("  ");
                }
                return sbl.delete(sbl.length() - 2, sbl.length()).toString();
            }
        }

        // NPS题
        if (CustomTypeEnum.NPS.equals(type)) {
            JSONArray options = JSON.parseArray(answerDTO.getAnswer());
            if (CollectionUtils.isEmpty(options)) {
                log.error("[Ticket] getNotifyQuestion parseAnswer error {}-{}", type.getName(), answerDTO);
                return null;
            }
            sbl.append("  ");
            for (int i = 0; i < options.size(); i++) {
                JSONObject option = options.getJSONObject(i);
                sbl.append("分数: ").append(option.getString("score")).append(" ");
                int score = Integer.parseInt(option.getString("score"), 10);
                if (0 <= score && score <= 6) {
                    sbl.append("NPS客户类型：贬低者 (0-6分)");
                }
                if (7 <= score && score <= 8) {
                    sbl.append("NPS客户类型：中立者 (7-8分)");
                }
                if (9 <= score && score <= 10) {
                    sbl.append("NPS客户类型：推荐者 (9-10分)");
                }
            }
            return sbl.toString();
        }

        // 比重题
        if (CustomTypeEnum.PROPORTION.equals(type)) {
            JSONArray options = JSON.parseArray(answerDTO.getAnswer());
            if (CollectionUtils.isEmpty(options)) {
                log.error("[Ticket] getNotifyQuestion parseAnswer error {}-{}", type.getName(), answerDTO);
                return null;
            }
            sbl.append("  ");
            for (int i = 0; i < options.size(); i++) {
                JSONObject option = options.getJSONObject(i);
                sbl.append(option.getString("title")).append("：");
                sbl.append(option.getString("score")).append("  ");
            }
            return sbl.delete(sbl.length() - 2, sbl.length()).toString();
        }

        // 矩阵单选题 | 矩阵多选题
        if (CustomTypeEnum.MATRIX_SINGLE.equals(type) ||
                CustomTypeEnum.MATRIX_MULTIPLE.equals(type)) {
            JSONArray options = JSON.parseArray(answerDTO.getAnswer());
            if (CollectionUtils.isEmpty(options)) {
                log.error("[Ticket] getNotifyQuestion parseAnswer error {}-{}", type.getName(), answerDTO);
                return null;
            }
            sbl.append("  ");
            for (int i = 0; i < options.size(); i++) {
                JSONObject option = options.getJSONObject(i);
                sbl.append(option.getString("title")).append("：");
                JSONArray innerOptions = option.getJSONArray("answer");
                for (int j = 0; j < innerOptions.size(); j++) {
                    JSONObject innerOption = innerOptions.getJSONObject(j);
                    sbl.append(innerOption.getString("title"));
                    if (innerOption.containsKey("open")) {
                        sbl.append("（").append(innerOption.getString("open")).append("）");
                    }
                    sbl.append(" | ");
                }
                sbl.append("  ");
            }
            return sbl.delete(sbl.length() - 2, sbl.length()).toString();
        }

        // 矩阵填空题
        if (CustomTypeEnum.MATRIX_BLANK.equals(type)) {
            JSONArray options = JSON.parseArray(answerDTO.getAnswer());
            if (CollectionUtils.isEmpty(options)) {
                log.error("[Ticket] getNotifyQuestion parseAnswer error {}-{}", type.getName(), answerDTO);
                return null;
            }
            sbl.append("  ");
            for (int i = 0; i < options.size(); i++) {
                JSONObject option = options.getJSONObject(i);
                sbl.append(option.getString("title")).append(" ");
                JSONArray innerOptions = option.getJSONArray("answer");
                for (int j = 0; j < innerOptions.size(); j++) {
                    JSONObject innerOption = innerOptions.getJSONObject(j);
                    sbl.append(innerOption.getString("title")).append("：");
                    sbl.append(innerOption.getString("blank")).append(" | ");
                }
                sbl.delete(sbl.length() - 3, sbl.length());
                if (StringUtils.isNotEmpty(option.getString("open"))) {
                    sbl.append(" (");
                    sbl.append(option.getString("open")).append(")");
                }
                sbl.append("  ");
            }
            return sbl.delete(sbl.length() - 2, sbl.length()).toString();
        }

        // 矩阵打分题
        if (CustomTypeEnum.MATRIX_SCORE.equals(type)) {
            JSONArray options = JSON.parseArray(answerDTO.getAnswer());
            if (CollectionUtils.isEmpty(options)) {
                log.error("[Ticket] getNotifyQuestion parseAnswer error {}-{}", type.getName(), answerDTO);
                return null;
            }
            sbl.append("  ");
            for (int i = 0; i < options.size(); i++) {
                JSONObject option = options.getJSONObject(i);
                sbl.append(option.getString("title")).append("  ");
                JSONArray innerOptions = option.getJSONArray("answer");
                for (int j = 0; j < innerOptions.size(); j++) {
                    JSONObject innerOption = innerOptions.getJSONObject(j);
                    sbl.append(innerOption.getString("title")).append("：");
                    sbl.append(innerOption.getString("score")).append(" | ");
                }
                sbl.delete(sbl.length() - 3, sbl.length());
                sbl.append("  ");
            }
            return sbl.delete(sbl.length() - 2, sbl.length()).toString();
        }

        // 姓名题 | 邮箱题
        if (CustomTypeEnum.INFO_USERNAME.equals(type) ||
                CustomTypeEnum.INFO_EMAIL.equals(type) ||
                CustomTypeEnum.INFO_PHONE.equals(type)) {
            JSONArray blanks = JSON.parseArray(answerDTO.getAnswer());
            if (CollectionUtils.isEmpty(blanks)) {
                log.error("[Ticket] getNotifyQuestion parseAnswer error {}-{}", type.getName(), answerDTO);
                return null;
            }
            sbl.append("  ");
            for (int i = 0; i < blanks.size(); i++) {
                JSONObject blank = blanks.getJSONObject(i);
                sbl.append(blank.getString("blank")).append("  ");
            }
            return sbl.delete(sbl.length() - 2, sbl.length()).toString();
        }

        // 时间题
        if (CustomTypeEnum.INFO_TIME.equals(type)) {
            // 秒数; 小时 * 60 * 60 + 分钟 * 60
            int seconds = Integer.parseInt(answerDTO.getAnswer());
            int minutes = seconds / 60;
            int hours = minutes / 60;
            sbl.append("  ").append(hours).append(":").append(minutes - (hours * 60));
            return sbl.toString();
        }

        // 日期题
        if (CustomTypeEnum.INFO_DATE.equals(type)) {
            JSONObject answer = JSON.parseObject(answerDTO.getAnswer());
            if (Objects.isNull(answer)) {
                log.error("[Ticket] getNotifyQuestion parseAnswer error {}-{}", type.getName(), answerDTO);
                return null;
            }
            String ts = answer.getString("ts"), tz = answer.getString("tz");
            if (ObjectUtils.isEmpty(ts)) {
                log.error("[Ticket] getNotifyQuestion parseAnswer ts error {}-{}", type.getName(), answerDTO);
                return null;
            }
            if (ObjectUtils.isEmpty(tz)) {
                tz = "+8";
            }
            if (tz.lastIndexOf('+') == -1) {
                tz = "+" + tz;
            }

            ts = ts + "000";
            long timestamp = Long.parseLong(ts);
            Instant instant = Instant.ofEpochMilli(timestamp);
            LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.of(tz));
            sbl.append("时间: ").append(DateTimeFormatter.ofPattern("yyyy/MM/dd").format(localDateTime));
            return sbl.toString();
        }

        // 地理位置题
        if (CustomTypeEnum.INFO_GEOGRAPHY.equals(type)) {
            JSONObject address = JSON.parseObject(answerDTO.getAnswer());
            if (Objects.isNull(address)) {
                log.error("[Ticket] getNotifyQuestion parseAnswer error {}-{}", type.getName(), answerDTO);
                return null;
            }
            sbl.append("地址：").append(address.getString("formattedAddress"));
            List<String> coordinate = address.getJSONArray("coordinate").toJavaList(String.class);
            if (!CollectionUtils.isEmpty(coordinate) && coordinate.size() == 2) {
                BigDecimal latitude = new BigDecimal(coordinate.get(0)).setScale(2, RoundingMode.HALF_UP);
                BigDecimal longitude = new BigDecimal(coordinate.get(1)).setScale(2, RoundingMode.HALF_UP);
                sbl.append("  ").append("经度：").append(latitude).append(" 纬度：").append(longitude);
            }
            return sbl.toString();
        }

        // 城市地址题
        if (CustomTypeEnum.CITY.equals(type)) {
            JSONArray answer = JSON.parseArray(answerDTO.getAnswer());
            if (CollectionUtils.isEmpty(answer)) {
                log.error("[Ticket] getNotifyQuestion parseAnswer error {}-{}", type.getName(), answerDTO);
                return null;
            }
            List<String> addressList = answer.toJavaList(String.class);
            if (CollectionUtils.isEmpty(addressList)) {
                log.error("[Ticket] getNotifyQuestion parseAnswer error {}-{}", type.getName(), answerDTO);
                return null;
            }
            sbl.append("  ");
            for (int i = 0; i < addressList.size() - 1; i++) {
                sbl.append(addressList.get(i)).append("-");
            }
            sbl.delete(sbl.length() - 1, sbl.length());
            sbl.append("  ").append("详细地址：").append(addressList.get(addressList.size() - 1));
            return sbl.toString();
        }

        // 评价题
        if (CustomTypeEnum.EVALUATION.equals(type)) {
            JSONObject answer = JSON.parseObject(answerDTO.getAnswer());
            if (Objects.isNull(answer)) {
                log.error("[Ticket] getNotifyQuestion parseAnswer error {}-{}", type.getName(), answerDTO);
                return null;
            }
            sbl.append("  ");
            int score = Integer.parseInt(answer.getString("score"));
            sbl.append("分数：").append(score);

            List<String> tagsId = answer.getJSONArray("tagsId").toJavaList(String.class);
            JSONObject template = JSON.parseObject(answerDTO.getCurrentTemplate());
            if (!CollectionUtils.isEmpty(tagsId)) {
                sbl.append(" ").append("标签: ");
                JSONObject tagListJson = template.getJSONObject("tagList");
                Map<String, Object> tagList = tagListJson.getInnerMap();
                for (String tagId : tagsId) {
                    String title = tagId;
                    if (tagList.containsKey(tagId)) {
                        Object tag = tagList.get(tagId);
                        if (tag instanceof JSONObject) {
                            title = ((JSONObject) tag).getString("title");
                        }
                    }
                    sbl.append(title).append("、");
                }
                sbl.delete(sbl.length() - 1, sbl.length());
            }

            String open = answer.getString("open");
            if (!ObjectUtils.isEmpty(open)) {
                sbl.append(" ").append("留言：").append(open);
            }


            return sbl.toString();
        }

        // 分类题
        if (CustomTypeEnum.CLASSIFY.equals(type)) {
            JSONArray options = JSON.parseArray(answerDTO.getAnswer());
            if (CollectionUtils.isEmpty(options)) {
                log.error("[Ticket] getNotifyQuestion parseAnswer error {}-{}", type.getName(), answerDTO);
                return null;
            }
            sbl.append("  ");
            for (int i = 0; i < options.size(); i++) {
                JSONObject option = options.getJSONObject(i);
                sbl.append(option.getString("title")).append("：");
                if (!option.containsKey("answer")) {
                    sbl.append("-").append("   ");
                    continue;
                }
                JSONArray innerOptions = option.getJSONArray("answer");
                if (!CollectionUtils.isEmpty(innerOptions)) {
                    for (int j = 0; j < innerOptions.size(); j++) {
                        JSONObject innerOption = innerOptions.getJSONObject(j);
                        sbl.append(innerOption.getString("title"));
                        if (innerOption.containsKey("open")) {
                            sbl.append("（").append(innerOption.getString("open")).append("）");
                        }
                        sbl.append(" | ");
                    }
                    sbl.delete(sbl.length() - 3, sbl.length());
                }
                sbl.append("   ");
            }
            return sbl.delete(sbl.length() - 2, sbl.length()).toString();
        }

        // 图片选择题
        if (CustomTypeEnum.IMAGE_SELECT.equals(type)) {
            JSONArray options = JSON.parseArray(answerDTO.getAnswer());
            if (CollectionUtils.isEmpty(options)) {
                log.error("[Ticket] getNotifyQuestion parseAnswer error {}-{}", type.getName(), answerDTO);
                return null;
            }
            sbl.append("  ");
            for (int i = 0; i < options.size(); i++) {
                JSONObject option = options.getJSONObject(i);
                sbl.append(option.getString("title"));
                sbl.append(" | ");
            }
            return sbl.delete(sbl.length() - 3, sbl.length()).toString();
        }

        // 自增表格题
        if (CustomTypeEnum.AUTO_TABLE.equals(type)) {
            JSONArray options = JSON.parseArray(answerDTO.getAnswer());
            if (CollectionUtils.isEmpty(options)) {
                log.error("[Ticket] getNotifyQuestion parseAnswer error {}-{}", type.getName(), answerDTO);
                return null;
            }
            JSONObject option = options.getJSONObject(0);
            JSONArray optionAns = option.getJSONArray("answer");
            sbl.append(Optional.ofNullable(optionAns).map(List::size).orElse(0)).append("行");
            return sbl.toString();
        }

        // 排序题
        if (CustomTypeEnum.SORT.equals(type)) {
            JSONArray options = JSON.parseArray(answerDTO.getAnswer());
            if (CollectionUtils.isEmpty(options)) {
                log.error("[Ticket] getNotifyQuestion parseAnswer error {}-{}", type.getName(), answerDTO);
                return null;
            }
            sbl.append("  ");

            String[] sortArray = new String[options.size() + 1];
            for (int i = 0; i < options.size(); i++) {
                JSONObject option = options.getJSONObject(i);
                StringBuilder optionStr = new StringBuilder();
                optionStr.append(option.getString("title"));
                String sort = option.getString("sort");
                if (sort.lastIndexOf('[') != -1) {
                    List<String> temp = option.getJSONArray("sort").toJavaList(String.class);
                    optionStr.append("(").append(temp.get(1)).append(")");
                    int rank = Integer.parseInt(temp.get(0), 10);
                    sortArray[rank] = optionStr.toString();
                } else {
                    int rank = Integer.parseInt(sort, 10);
                    sortArray[rank] = optionStr.toString();
                }
            }
            for (int i = 1; i < sortArray.length; i++) {
                sbl.append(i).append(".").append(sortArray[i]).append("  ");
            }

            return sbl.delete(sbl.length() - 2, sbl.length()).toString();
        }

        // 备注说明
        if (CustomTypeEnum.DESCRIPTOR.equals(type)) {
            return sbl.toString();
        }

        // 横向填空题(似乎没有了) | 分页(跳过)
        if (CustomTypeEnum.HORZ_BLANK.equals(type) ||
                CustomTypeEnum.PAGE.equals(type)) {
            return null;
        }
        return null;
    }
}
